<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label=" 0发布，1已付款，2认领中，3完成,，4问题订单" prop="state">
      <el-input v-model="dataForm.state" placeholder=" 0发布，1已付款，2认领中，3完成,，4问题订单"></el-input>
    </el-form-item>
    <el-form-item label="订单标题" prop="title">
      <el-input v-model="dataForm.title" placeholder="订单标题"></el-input>
    </el-form-item>
    <el-form-item label="订单内容" prop="content">
      <el-input v-model="dataForm.content" placeholder="订单内容"></el-input>
    </el-form-item>
    <el-form-item label="订单备注" prop="remarks">
      <el-input v-model="dataForm.remarks" placeholder="订单备注"></el-input>
    </el-form-item>
    <el-form-item label="订单图片" prop="orderImg">
      <el-input v-model="dataForm.orderImg" placeholder="订单图片"></el-input>
    </el-form-item>
    <el-form-item label="订单首页图片" prop="indexImg">
      <el-input v-model="dataForm.indexImg" placeholder="订单首页图片"></el-input>
    </el-form-item>
    <el-form-item label="取物位置" prop="location">
      <el-input v-model="dataForm.location" placeholder="取物位置"></el-input>
    </el-form-item>
    <el-form-item label="发布人id" prop="issueUser">
      <el-input v-model="dataForm.issueUser" placeholder="发布人id"></el-input>
    </el-form-item>
    <el-form-item label="接单人id" prop="belongUser">
      <el-input v-model="dataForm.belongUser" placeholder="接单人id"></el-input>
    </el-form-item>
    <el-form-item label="订单创建时间" prop="createTime">
      <el-input v-model="dataForm.createTime" placeholder="订单创建时间"></el-input>
    </el-form-item>
    <el-form-item label="接单时间" prop="receiveTime">
      <el-input v-model="dataForm.receiveTime" placeholder="接单时间"></el-input>
    </el-form-item>
    <el-form-item label="订单完成时间" prop="overTime">
      <el-input v-model="dataForm.overTime" placeholder="订单完成时间"></el-input>
    </el-form-item>
    <el-form-item label="是否匿名0不匿名，1匿名" prop="hideName">
      <el-input v-model="dataForm.hideName" placeholder="是否匿名0不匿名，1匿名"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          state: '',
          title: '',
          content: '',
          remarks: '',
          orderImg: '',
          indexImg: '',
          location: '',
          issueUser: '',
          belongUser: '',
          createTime: '',
          receiveTime: '',
          overTime: '',
          hideName: ''
        },
        dataRule: {
          state: [
            { required: true, message: ' 0发布，1已付款，2认领中，3完成,，4问题订单不能为空', trigger: 'blur' }
          ],
          title: [
            { required: true, message: '订单标题不能为空', trigger: 'blur' }
          ],
          content: [
            { required: true, message: '订单内容不能为空', trigger: 'blur' }
          ],
          remarks: [
            { required: true, message: '订单备注不能为空', trigger: 'blur' }
          ],
          orderImg: [
            { required: true, message: '订单图片不能为空', trigger: 'blur' }
          ],
          indexImg: [
            { required: true, message: '订单首页图片不能为空', trigger: 'blur' }
          ],
          location: [
            { required: true, message: '取物位置不能为空', trigger: 'blur' }
          ],
          issueUser: [
            { required: true, message: '发布人id不能为空', trigger: 'blur' }
          ],
          belongUser: [
            { required: true, message: '接单人id不能为空', trigger: 'blur' }
          ],
          createTime: [
            { required: true, message: '订单创建时间不能为空', trigger: 'blur' }
          ],
          receiveTime: [
            { required: true, message: '接单时间不能为空', trigger: 'blur' }
          ],
          overTime: [
            { required: true, message: '订单完成时间不能为空', trigger: 'blur' }
          ],
          hideName: [
            { required: true, message: '是否匿名0不匿名，1匿名不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/bbm/findowner/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.state = data.findOwner.state
                this.dataForm.title = data.findOwner.title
                this.dataForm.content = data.findOwner.content
                this.dataForm.remarks = data.findOwner.remarks
                this.dataForm.orderImg = data.findOwner.orderImg
                this.dataForm.indexImg = data.findOwner.indexImg
                this.dataForm.location = data.findOwner.location
                this.dataForm.issueUser = data.findOwner.issueUser
                this.dataForm.belongUser = data.findOwner.belongUser
                this.dataForm.createTime = data.findOwner.createTime
                this.dataForm.receiveTime = data.findOwner.receiveTime
                this.dataForm.overTime = data.findOwner.overTime
                this.dataForm.hideName = data.findOwner.hideName
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/bbm/findowner/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'state': this.dataForm.state,
                'title': this.dataForm.title,
                'content': this.dataForm.content,
                'remarks': this.dataForm.remarks,
                'orderImg': this.dataForm.orderImg,
                'indexImg': this.dataForm.indexImg,
                'location': this.dataForm.location,
                'issueUser': this.dataForm.issueUser,
                'belongUser': this.dataForm.belongUser,
                'createTime': this.dataForm.createTime,
                'receiveTime': this.dataForm.receiveTime,
                'overTime': this.dataForm.overTime,
                'hideName': this.dataForm.hideName
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
